package com.obtk.property.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 地址映射
 */
@Configuration
public class UploadConfig implements WebMvcConfigurer {
//     application.properties  获取变量  上传地址
    @Value("${file.upload.path}")
    private String filePath;

    // 显示相对地址
    @Value("${file.upload.path.relative}")
    private String fileRelativePath;

//    地址映射 url地址与本地磁盘地址映射
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 读取本地文件需要加上 file:/
        registry.addResourceHandler(fileRelativePath).addResourceLocations("file:/" + filePath);
    }
}
